package club.banyuan.SpringBootHrms.controller;

import club.banyuan.SpringBootHrms.dto.AnimalInputDto;
import club.banyuan.SpringBootHrms.dto.ApiResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

// 这个注解 就是相当于加了@ResponseBody 直接返回文本
@RestController
@RequestMapping("/result")
public class TestResultController {
    @GetMapping("/string")
    public String getString() {
        return "login";
    }

    @GetMapping("/map")
    public Map getMap() {
        Map<String,Object> map = new HashMap<>();
        map.put("name","giraffe");
        map.put("category",1);
        // 都是用json传递
        return map;
    }

    @GetMapping("/entity")
    public AnimalInputDto getEntity() {
        AnimalInputDto animal = new AnimalInputDto();
        animal.setName("giraffe");
        animal.setCategory(1);
        // 返回实体类
        return animal;
    }

    @GetMapping("/result")
    public ApiResult<AnimalInputDto> getApiResult() {
        return ApiResult.success(getEntity());
    }

    @GetMapping("/success")
    public ApiResult getSuccess() {
        return ApiResult.success();
    }
}
